//
//  ViewController.swift
//  SyanYan
//
//  Created by Yanyan Jiang on 2018/5/26.
//  Copyright © 2018年 Yanyan Jiang. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.configureSubviews()
//        self.possibleValueMethod()
//        self.classAndClass()
        self.controlsDefault()//自定义控件方法
    }
    
    public  func configureSubviews() -> () {
        
        let btn:UIButton = UIButton(frame: CGRect(x:self.view.center.x, y:self.view.center.y, width: 100, height: 100))
        btn.backgroundColor = UIColor.magenta
        btn.setTitle("普通状态", for: UIControlState.normal)
        btn.setTitleColor(UIColor.white, for: .normal)
        btn.setTitle("选中状态", for: .selected)
        btn.setTitleColor(UIColor.black, for: .selected)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        btn.layer.cornerRadius = 5;
        btn.layer.masksToBounds = true
        btn.addTarget(self, action: #selector(click(_:)), for: .touchUpInside)
        self.view.addSubview(btn)

        
        let lab: UILabel = UILabel(frame: CGRect(x:30, y:170, width:300, height:36))
        lab.text = "你好swift"
        lab.textColor = UIColor.magenta
        self.view.addSubview(lab)
        var x = 100
        x = 200
        lab.tag = x
        print("Hello \(x)")
        
        let components = "~/Documents/JiangYanYan".completePath(caseSensitive: true)
        print("哥哥\(components)")
        for character in "我最爱你了，🇨🇳🐩🦆🐤" {
            print("妹妹 \(character)")
        }
        //合并字符串与字符Combining Stings and characters
        let china = "🇨🇳"
        let video = "人民好"
        print("\(china+video)")
        //构建复杂字符串
        let a = 3 , b = 9
        let mathResult = "\(a) 乘以 \(b) 等于 \(a * b)"
        print("\(mathResult)")
        //字符串相关操作
        var variableString = "小明"
        variableString += "和小刚"
        print("\(variableString)")
        
        //数组和字典的字面量 Array and Dictionary Literals  类型化的集合 Typed Collections
        var names87 = ["小明", "小刚", "三桑", "乐风"];//只能放字符串类型
        names87[0] = "啤酒"
        names87[1...3] = ["毛豆", "黄瓜"]
        print("\(names87)")
        
        var numberOfLegs = ["ant":6, "snake":0, "dog":4, "cat": 4]//键只能是字符串 值只能是int
        numberOfLegs["蜘蛛"] = 273
        numberOfLegs["蜘蛛"] = 8
        for (animalName, legCount) in numberOfLegs {
            print("一只\(animalName)\(legCount)条腿")
        }
        //...全闭  ..半闭半开
        for number in 1...5 {
            print("\(number) 3 得 \(number * 3)")
        }
    }
    
    func possibleValueMethod() -> () {
        var numberOfLegs = ["ant":6, "snake":0, "dog":4, "cat": 4]
        //可能值
        let possibleLegCount: Int? = numberOfLegs["章鱼"]
        //        if possibleLegCount == nil{
        //            print("章鱼没有腿")
        //        }else{
        //            // !表示强制解包
        //            let legCount = possibleLegCount!
        //            print("章鱼有\(legCount)条腿")
        //        }
        
        if (possibleLegCount != nil) {
            let legCount = possibleLegCount!//可能值解包
            print("章鱼有\(legCount)条腿")
        }
        if let legC = possibleLegCount {
            print("章鱼有\(legC)条腿")
            switch legC {
            case 1,3,5:
                break
                
            case 2,4,6:
                break
                //闭合区间
            case 8...20:
                
                break
                //半闭半开区间
            case 21..<30:
                
                break
            default:
                break
            }
        }
    }
    
    //类与类的导入
    func classAndClass() -> () { 
        let customVC: CustomViewControllerOne = CustomViewControllerOne()
        customVC.learnSwiftMethod()
        customVC.classInitPropertyMethod()
        //两个参数一个返回值
        let strReturn = customVC.parameterMethods(name: "大海", age: 28)
        print(strReturn)
        
        let A002VC: A002ViewController = A002ViewController()
        A002VC.optionalNumberPractice()
    }
    
    //变量、字符串、集合、循环语句#pragma mark -addTarget
    //constants and variables 常量与变量 优先考虑定义let 这样会提高运行速度，不行再考虑var
    var languageName: String = "Swift"
    let version: Double = 1.0
    var year: Int = 2018
    var isWeSame :Bool = false
    //不显示写一个变量的类型  通过类型推导 Type Inference  这样写不是没有类型，是编译器根据类型推导推导出来的只是你不用写不用声明而已
    let languageN = "IOS"
    let version1 = 2.0
    var year1 = 1991
    let isMeiMei = true
   // Unicode Names unicode 命名
    let π = 3.1415926
    let 🐂🐶 = "牛狗"
    //oc中需要的字符串可以用swift字符直接赋值过去
    
    
    //自定义控件
    func controlsDefault() -> () {
        let controlVC:ControlsViewController = ControlsViewController()
        controlVC.controlsMethod()
        print("\(controlVC.pppp)")
    }
    
    @objc func click(_ sender: UIButton){
        print("传递触摸对象")
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}

